#include "RobotStateMonitor.h"
#include "ui_RobotStateMonitor.h"

RobotStateMonitor::RobotStateMonitor(const RobotBaseData& baseData,
                                     const RobotNetData& netData,
                                     QWidget *parent) :
    QWidget(parent),
    ui(new Ui::RobotStateMonitor)
{
    ui->setupUi(this);

    ui->groupBox->setTitle(QString::asprintf("机器 %d ", baseData.num));
    ui->lineEditID->setText(QString::asprintf("AMR_%d ", baseData.num));
    ui->lineEditIP->setText(netData.ip);
    ui->spinBoxX->setValue( baseData.x );
    ui->spinBoxY->setValue( baseData.y );
    ui->spinBoxTheta->setValue( baseData.theta );

    //连接属性
    ui->btnConnect->setText("连接");
    ui->btnConnect->setStyleSheet("background-color:rgb(46, 247, 125);border-color:rgb(46, 247, 125);");
    m_netData.isConnect = false;
}

RobotStateMonitor::~RobotStateMonitor()
{
    delete ui;
}

void RobotStateMonitor::setData(const RobotBaseData& data)
{
    m_baseData = data;
    ui->spinBoxX->setValue( m_baseData.x );
    ui->spinBoxY->setValue( m_baseData.y );
    ui->spinBoxTheta->setValue( m_baseData.theta );
}

void RobotStateMonitor::on_pushButton_clicked()
{
    m_baseData.x = ui->spinBoxX->value();
    m_baseData.y = ui->spinBoxY->value();
    m_baseData.theta = ui->spinBoxTheta->value();

    emit sendData(m_baseData);
}

void RobotStateMonitor::on_btnConnect_clicked()
{
    if ( !m_netData.isConnect ) {
        ui->btnConnect->setText("断开");
        ui->btnConnect->setStyleSheet("background-color:rgba(221, 68, 10, 100);border-color:rgb(221, 68, 10);");
        m_netData.isConnect = true;
    }
    else {
        ui->btnConnect->setText("连接");
        ui->btnConnect->setStyleSheet("background-color:rgb(46, 247, 125, 100);border-color:rgb(46, 247, 125);");
        m_netData.isConnect = false;
    }
}
